package com.imooc.bilibili.controller;

import com.imooc.bilibili.es_service.ElasticsearchService;
import com.imooc.bilibili.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system-es")
public class SystemController {

    @Autowired
    private ElasticsearchService esService;

    @GetMapping("/contents-query")
    public Result<List<Map<String,Object>>> getContents(@RequestParam String keyWord,
                                                        @RequestParam Integer pageNo,
                                                        @RequestParam Integer pageSize) throws IOException {
        List<Map<String, Object>> contents = esService.getContents(keyWord, pageNo, pageSize);
        return new Result<>(contents);
    }
}
